<?php
/**
 * Created by PhpStorm.
 * User: mark
 * Date: 18-10-21
 * Time: 下午5:07
 */
namespace Event;

class EventCenter{

  public static function default(){
    return new EventCenter();
  }

  /**
   * 抛出事件并触发处理程序
   * @param Event $event
   * @throws \Exception
   */
  public function postEvent(Event $event){
    $class_name = $event->getId();
    if (!array_key_exists($class_name,EventAutoRegister::$allListeners)){
      throw new \Exception($class_name." is not register");
    }
    foreach (EventAutoRegister::$allListeners[$class_name] as $listener){
      /**
       * @var $listener Listener
       */
      Listener::New($listener,$event)->handler();
    }
  }
}